// 定义全局方法

//封装过期控制代码
function setLocalStorage(key,value){
    const curTime = new Date().getTime();
    localStorage.setItem(key,JSON.stringify({data:value,time:curTime}));
}
function getLocalStorage(key,exp){
    const data = localStorage.getItem(key);
    const dataObj = JSON.parse(data);
    if (new Date().getTime() - dataObj.time>exp) {
        console.log('信息已过期');
        this.$router.push("/");
    }else{
        return JSON.parse(dataObj.data);
    }
}

export default {
    setLocalStorage,
    getLocalStorage,
}